var hero_list_Data = require('./hero_list_Data')();
var GameData = require('../../module/GameData')();




cc.Class({
    extends: cc.Component,

    properties: {
        title:cc.Label,
        hero_list: cc.ScrollView,
        hero_list_item:cc.Prefab,
        hero_property:cc.Node,

    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        GameData.hero_layer=this;

        this.title.string=hero_list_Data.title;

        this.content = this.hero_list.content;
        this.initList();
        var fun=function(){};
        cc.find("loadbg").getComponent("loadbg").show(fun);
    },

    start () {



    },
    initList() {
        var data = hero_list_Data.heroArr;
        var Arr=[];
        for(let a=0;a<data.length;a++){
            let idx=Math.ceil((a+1)/2);
            if(typeof Arr[idx-1]!=="object"){
                Arr[idx-1]=[];
            }
            Arr[idx-1].push(data[a]);
        }
        console.log(Arr);
        for(let a=0;a<Arr.length;a++){
            var item=cc.instantiate(this.hero_list_item);
            item.getComponent("hero_listitem").create_hero(Arr[a]);
            this.content.addChild(item);

        }

        // for (var a = 0; a < data.length; a++) {
        //     let item = cc.instantiate(this.player_list_item);
        //     item.getComponent('player_list_item').init(data[a]);
        //     this.content.addChild(item);
        // }
    },

    // update (dt) {},
});
